﻿using System;
using System.Threading;
using System.Threading.Tasks;
using TouchSocket.Http;

namespace wx_api.NetLIB
{
    public class BigDataHttpContent : TouchSocket.Http.HttpContent
    {
        long count = 10000;
        long bufferLength = 1000000;

        protected override bool OnBuildingContent<TByteBlock>(ref TByteBlock byteBlock)
        {
            return false;
        }

        protected override void OnBuildingHeader(IHttpHeader header)
        {
            header.Add(HttpHeaders.ContentLength, (count * bufferLength).ToString());
        }

        protected override async Task WriteContent(Func<ReadOnlyMemory<byte>, Task> writeFunc, CancellationToken token)
        {
            var buffer = new byte[bufferLength];
            for (int i = 0; i < count; i++)
            {
                await writeFunc.Invoke(buffer);
                //Console.WriteLine(i);
            }
        }
    }
}
